/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chatroom.com.util;
 
import java.sql.*;
/**
 * 数据库常用操作
 * @author Administrator
 *
 */
public class DbManager {
	public static Connection getConnection(){
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			// 获取连接3306指数据库端口，txtlpf指数据库database名，root\123分别是数据库用户名和密码
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/chatRoom","root","ROOT");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;				
	}
	
	public static ResultSet getResult(String sql){
		Statement st = null;
		try {
			st = DbManager.getConnection().createStatement();
		} catch (SQLException e) {
			 
			e.printStackTrace();
		}
		ResultSet rs = null;
		try {
			rs = st.executeQuery(sql);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return rs;
	}
}
